home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / STICK.ASM < prev    next >
Assembly Source File  |  1987-08-27  |  21KB  |  469 lines

  1. ;STICK.COM for the IBM Personal Computer - 1987 by Jeff Prosise
  2. ;     [d:][path]STICK [/L+|-] [/E+|-] [/B+|-] [/C-| fg bg] 
  3.  
  4. bios_data     segment at 40h
  5.  
  6.               org 60h
  7. bios_cursor   dw ?                          ;cursor mode
  8.               org 63h
  9. addr_6845     dw ?                          ;CRT Controller base address
  10.               org 87h
  11. ega_info      db ?                          ;EGA info byte
  12.  
  13. bios_data     ends
  14.  
  15. ;======================================================================
  16. code          segment para public 'code'
  17.               assume cs:code
  18.               org 100h
  19.  
  20. begin:        jmp stick
  21.  
  22. copyright     db "STICK 1.0 (c) 1987 Ziff Communications Co.",13,10,"$",1Ah
  23. author        db "Jeff Prosise"
  24.  
  25. locking       db 0FFh                       ;state of cursor locking
  26. emulation     db 0FFh                       ;state of EGA cursor emulation
  27. foreground    db 0FFh                       ;selected foreground color
  28. background    db 0                          ;selected background color
  29.  
  30. cursor_mode   dw 0                          ;desired cursor definition
  31. adapter       db 2                          ;0=MDA or CGA, 1=EGA, 2=VGA
  32. old_video     label dword
  33. old10h        dw 0,0                        ;interrupt 10h vector
  34.  
  35. ;-----------------------------------------------------------------------------
  36. ;VideoInt intercepts calls to interrupt 10h.
  37. ;-----------------------------------------------------------------------------
  38. VideoInt      proc near
  39.  
  40.               sti                           ;enable interrupts
  41.               cmp ah,6                      ;check for scroll function
  42.               jb noscroll
  43.               cmp ah,7
  44.               ja pass
  45. ;
  46. ;Check the color selection for screen clear if color locking is on.
  47. ;
  48.               or al,al                      ;AL = 0 (clear screen)?
  49.               jne pass                      ;no, then pass thru to BIOS
  50.               test cs:[foreground],80h      ;color locking active?
  51.               jnz pass                      ;no, then pass thru to BIOS
  52.               cmp bh,7                      ;white-on-black?
  53.               jne pass                      ;no, then let it go
  54.               mov bh,cs:[background]        ;reset attribute in BH
  55.               push cx
  56.               mov cl,4
  57.               shl bh,cl
  58.               pop cx
  59.               or bh,cs:[foreground]
  60. pass:         jmp old_video                 ;pass modified parm to BIOS
  61. ;
  62. ;See if the cursor mode is to be modified.
  63. ;
  64. noscroll:     cmp ah,1                      ;cursor mode function?
  65.               jne pass                      ;no, then pass to BIOS
  66.               test ch,20h                   ;call to blank the cursor?
  67.               jnz pass                      ;yes, then pass to BIOS
  68. ;
  69. ;Alter the cursor definition in CX if cursor locking is on.
  70. ;
  71.               cmp cs:[locking],0FFh         ;locking function active?
  72.               je nolock                     ;no, then check emulation function
  73.               push ax                       ;save registers
  74.               push cx
  75.               push dx
  76.               push es
  77.               mov cx,cs:[cursor_mode]       ;get new cursor value
  78.               call SetCursorMode
  79.               pop es                        ;restore registers
  80.               pop dx
  81.               pop cx
  82.               pop ax
  83.               iret
  84. ;
  85. ;See if emulation should be performed.
  86. ;
  87. nolock:       cmp cs:[emulation],0FFh       ;emulation function active?
  88.               je pass                       ;no, then pass control to BIOS
  89.               cmp cs:[adapter],1            ;EGA installed?
  90.               jne pass                      ;no, then pass control to BIOS
  91.               push ax                       ;save registers
  92.               push es
  93.               mov ax,bios_data              ;make sure EGA is active
  94.               mov es,ax
  95.     assume es:bios_data
  96.               test es:[ega_info],8
  97.               jnz exit                      ;exit if it's not
  98.               test es:[ega_info],1          ;emulation bit set?
  99.               jnz exit                      ;yes, then exit
  100.               push bx                       ;save remaining registers
  101.               push cx
  102.               push dx
  103. ;
  104. ;Determine whether or not this call was intended for a CGA.
  105. ;
  106.               cmp cl,7                      ;CGA-type cursor?
  107.               ja setmode                    ;no, then don't alter values
  108.               or cl,cl                      ;EGA ending line?
  109.               je setmode                    ;yes, then don't touch it
  110. ;
  111. ;Scale the starting and ending scan lines.
  112. ;
  113.               mov bx,cx                     ;transfer cursor mode to BX
  114.               mov ax,1130h                  ;determine bytes per character
  115.               int 10h                       ;points in CX
  116.               mov al,cl                     ;transfer points to al
  117.               dec al                        ;determine last scan line
  118.               sub al,bl                     ;calculate adjustment value
  119.               or bh,bh                      ;adjust starting scan line?
  120.               je endline                    ;not if it's zero
  121.               add bh,al                     ;adjust it
  122. endline:      add bl,al                     ;scale ending line
  123.               cmp bx,0C0Dh                  ;normal EGA underline cursor?
  124.               jne skip
  125.               mov bx,0B0Ch                  ;yes, then raise it a line
  126. skip:         inc bl                        ;adjust ending line for EGA
  127.               cmp bl,cl                     ;wrap around if necessary
  128.               jne nowrap
  129.               xor bl,bl
  130. nowrap:       or bx,bx                      ;full height cursor?
  131.               jne notfull
  132.               mov bl,1Eh                    ;adjust for full height
  133. notfull:      mov cx,bx                     ;transfer value back to CX
  134. ;
  135. ;Set the cursor and exit.
  136. ;
  137. setmode:      call SetCursorMode            ;set the cursor
  138.               pop dx                        ;restore registers and exit
  139.               pop cx
  140.               pop bx
  141.               pop es
  142.               pop ax
  143.               iret
  144. ;
  145. ;Exit to the BIOS interrupt handling code.
  146. ;
  147. exit:         pop es                        ;exit to BIOS
  148.               pop ax
  149.               jmp cs:old_video
  150. VideoInt      endp
  151.  
  152. ;-----------------------------------------------------------------------------
  153. ;SetCursorMode sets the cursor to the scan lines indicated in CX.
  154. ;-----------------------------------------------------------------------------
  155. SetCursorMode proc near
  156.               mov ax,bios_data              ;address BIOS data area with ES
  157.               mov es,ax
  158.     assume es:bios_data
  159.               mov es:[bios_cursor],cx       ;store cursor mode
  160.               mov dx,es:[addr_6845]         ;get CRTC address
  161.               mov al,10                     ;out CH and CL to cursor registers
  162.               out dx,al
  163.               inc dx
  164.               mov al,ch
  165.               out dx,al
  166.               dec dx
  167.               mov al,11
  168.               out dx,al
  169.               inc dx
  170.               mov al,cl
  171.               out dx,al
  172.               ret
  173. SetCursorMode endp
  174.  
  175. lastbyte      equ $
  176.  
  177. ;-----------------------------------------------------------------------------
  178. ;Stick routine receives control when the program is run.
  179. ;-----------------------------------------------------------------------------
  180. line1         db 13,10,"Cursor Locking:      $"
  181. line2         db       "Color Locking:       $"
  182. line3         db       "Emulation Mode:      $"
  183. line4         db       "EGA Emulation Bit:   $"
  184.  
  185. errmsg        db 13,10,"Usage: [d:][path]STICK [/L+|-] [/E+|-] "
  186.               db "[/B+|-] [/C-| fg bg]",13,10,"$"
  187. on            db "On",13,10,"$"
  188. off           db "Off",13,10,"$"
  189. bitvalue      db "0",13,10,"$"
  190.  
  191. stick         proc near
  192.               assume cs:code,ds:code,es:code,ss:code
  193. ;
  194. ;Determine what type of video adapter is installed.
  195. ;
  196.               mov ax,1A00h                  ;look for a VGA
  197.               int 10h
  198.               cmp al,1Ah
  199.